#!/bin/bash
# 部署收集堡垒机的syslog并滚动刷新

username="user1"
password="123456"

yum -y install git python3
git clone https://gitee.com/steeed/SdsShtermSyslog.git /opt/SdsShtermSyslog/
chmod -R 0777 /opt/SdsShtermSyslog

useradd "$username"
echo "$password" | passwd --stdin "$username"

tag_msg="# SHTERM SYSLOG CLIENT"
bashrc_path="/home/${username}/.bashrc"
grep -q -e "^${tag_msg}" $bashrc_path
if [ $? -ne 0 ]
then
    echo "${tag_msg} START" >> $bashrc_path
    echo "cd /opt/SdsShtermSyslog" >> $bashrc_path
    echo 'exec 4<&1 && exec 1>/dev/null' >> $bashrc_path
    echo 'git fetch --all && git reset --hard origin/master && git pull' >> $bashrc_path
    echo 'exec 1<&4' >> $bashrc_path
    echo "cd ~" >> $bashrc_path
    echo "python3 /opt/SdsShtermSyslog/bin/test_script.py" >> $bashrc_path
    echo "#python3 /opt/SdsShtermSyslog/bin/sds_shterm_syslog.py" >> $bashrc_path
    echo "exit" >> $bashrc_path
    echo "${tag_msg} END" >> $bashrc_path
fi

firewall-cmd --permanent --add-port=514/udp
firewall-cmd --reload
